let express = require('express')
let router = express.Router()

const { getsqlall, getone, getfun } = require('../db')

//get/dashboard/pie
//饼状图获取数据接口
router.get('/pie', async (req, res) => {
  //解析请求参数
  //操作数据库
  //编写sql语句
  let sql = `select article_type as name, count(*) as value from articles GROUP BY article_type`
  //执行sql语句返回结果
  const data = await getsqlall(sql)
  res.send({
    data,
    code: 0,
    message: '饼状图数据获取成功',
    result: '00000',
  })
})

//get/dashboard/bar
//柱状图获取数据接口
router.get('/bar', async (req, res) => {
  let sql = `select dayofmonth(updated_time) as day ,count(*) as total from articles GROUP BY day`
  const data = await getsqlall(sql)
  res.send({
    code: 0,
    data,
    message: '柱状图数据获取成功',
    result: '00000',
  })
})
module.exports = router
